/*!
 * 日期控件.
 * ecp.qzz.ui.calendar.js
 * 创建：QZZ
 * 日期：2014-03-01
 */
define(["qzz.date", "qzz.window","qzz.iupdown"], function() {
	
	var qzz = window.qzz;
	qzz.space("ui");
	/**
	 * 日期控件.
	 */
	qzz.ui.calendar = qzz.Class(qzz.ui.window, {
		/**
		 * 创建.
		 */
		_create:function(){
			this.base();
			this.className = "Calendar";
		    this.logInfo("calendar.create");
		    //周期类型.
			this.cyctypes = {
				second:	"second",
				minute:"minute",
				hour: "hour",
			    day : "day",
			    ten : "ten",
			    month : "month",
			    season : "season",
			    year : "year"
			};
			this.cyctype = this.getOption().cyctype || this.cyctypes.day;
			if(this.cyctype == this.cyctypes.hour || this.cyctype == this.cyctypes.minute 
	    			|| this.cyctype == this.cyctypes.second) {
	    		this.curCyctype = this.cyctypes.day;
	    	} else {
	    	    this.curCyctype = this.cyctype;
	    	}
			//定义月，及每月天数, 周，旬等	
		    this.monthCN = this.getI18n("qzz.monthsText", ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]);
		    this.seasonCN = this.getI18n("qzz.seasonText", ["第一季度", "第二季度", "第三季度", "第四季度"]);
			this.weeks = this.getI18n("qzz.weeksText", ["日", "一", "二", "三", "四", "五", "六"]);		
		    this.tenDays = this.getI18n("qzz.tendaysText", ["上旬","中旬","下旬"]); 
            //选择日期 
		    this.curDate = new Date();
		    this.curYear = this.curDate.getFullYear();
		    this.curMonth = this.curDate.getMonth() + 1;
		    this.curDay = this.curDate.getDate();
		    this.curWeek = this.curDate.getDay();
		    this.curHour = 0;
		    this.curMinute = 0;
		    this.curSecond = 0;
		    //今天日期
		    this.toYear = this.curYear;
		    this.toMonth = this.curMonth;
		    this.toDay = this.curDay;
		    this.toWeek = this.curWeek;
		    //最大日期，
		    this.maxYear = 9999;
	        this.maxMonth = 12;
	        this.maxDay = 31;
	        //最小日期
	        this.minYear = 1;
	        this.minMonth = 1;
	        this.minDay = 1;
	        
	        this.dateObj = new qzz.date();
	        
	        this.dateObj.setCycType(this.cyctype);
	        
	        this.hTime = new qzz.ui.input.updown(undefined, 
	        		{"cssPrefix":this._cssPrefix,"loop":true,"lockLength":2});
	        this.hTime.setWidth(45);
	        this.hTime.setMaxValue(23);
	        this.hTime.setMinValue(0);
	        this.mTime = new qzz.ui.input.updown(undefined, 
	        		{"cssPrefix":this._cssPrefix,"loop":true,"lockLength":2});
	        this.mTime.setWidth(45);
	        this.mTime.setMaxValue(59);
	        this.mTime.setMinValue(0);
	        this.mTime.setLockLength(2);
	        var _me = this;
	        this.mTime.bind("onchange", function(sender, ov, nv, loop) {
	        	if(loop) {
	        		if(ov > nv) {
	        			_me.hTime.upValue();
	        		} else {
	        			_me.hTime.downValue();
	        		}
	        	}
	        });
	        this.sTime = new qzz.ui.input.updown(undefined, 
	        		{"cssPrefix":this._cssPrefix,"loop":true,"lockLength":2});
	        this.sTime.setWidth(45);
	        this.sTime.setMaxValue(59);
	        this.sTime.setMinValue(0);
	        this.sTime.bind("onchange", function(sender, ov, nv, loop) {
	        	if(loop) {
	        		if(ov > nv) {
	        			_me.mTime.upValue();
	        		} else {
	        			_me.mTime.downValue();
	        		}
	        	}
	        });	        
	        //上一选择
		    this.priorSel = null;
		    this.showTime = this.getBooleanValue(this.getOption().showTime, false);
		    //单列控件，缓存只创建一次的dom,用于变更样式时修改样式
		    this.domList = {};
		    this.domIndex = 0;
		    this.dateSplit = "-";
		    this.timeSplit = ":";
		    this.dtSplit = /[- ]/g;
		    if(this.getOption().width == null || this.getOption().width == 10) {
		    	this.getOption().width = 192;
		    }
	    },
	    /**
	     * 渲染.
	     */
	    _render:function() {	 
	    	this.logInfo("calendar.render");
	    	if(this.thisWindow == null) {
	    	    this.thisWindow = this.createElement("table");
	    	} else if(this.thisWindow.tagName === "DIV") {
		    		var conTab = $(this.createElement("table"));
		    		conTab.attr("id", this.control.attr("id"));
		    		conTab.attr("name", this.control.attr("name"));
		    		conTab.attr("width", this.control.attr("width"));
		    		
		    		this.control.replaceWith(conTab);
		    		this.control = conTab;
		    		this.control.data("_ecpUI", this);
		    		this.thisWindow = conTab[0];
		    }
	    	var _this = this;
		    this.thisWindow.onclick = function() {
		    	if(typeof _this.onRectClick == "function") {
		    		_this.onRectClick();
		    	}
		    }
		    var sh = 0;
		    //窗口
	    	this.thisWindow.border = "0px";
	    	this.thisWindow.cellPadding = "0px";
			this.thisWindow.cellSpacing = "1px";
			this._addCssList(this.thisWindow, "dateTable");
			//年月选择区
			var row1 = this.thisWindow.insertRow(0);
			this.headBox = row1.insertCell(0);
			this._addCssList(this.headBox, "dateCell");
			this.headBox.style.height = "30px";
			sh += 30;
			
			//日期选择区
			var row2 = this.thisWindow.insertRow(1);
			this.bodyBox = row2.insertCell(0);
			this._addCssList(this.bodyBox, "dateCell");
			this.bodyBox.style.verticalAlign = "top";
			
			sh += 7 * 30;
			//选择时间区域
			var row3 = this.thisWindow.insertRow(2);
			this.timeBox = row3.insertCell(0);
			this.timeRow = row3;
			this.timeRow.style.height = "25px";
			this._addCssList(this.timeBox, "dateCell");
			var tab = this.createElement("TABLE");
			tab.style.margin = "auto";
			this.setStyle(tab, "noborder");
			this.timeBox.appendChild(tab);
			this._addCssList(this.timeBox, "weekCommonCell");
			var tr = tab.insertRow(0);
			var tdi = 0;
			this.hBox = tr.insertCell(tdi++);
			this._setHtml(tr.insertCell(tdi++), this.timeSplit, false);
			this.mBox = tr.insertCell(tdi++);
			this._setHtml(tr.insertCell(tdi++), this.timeSplit, false);
			this.sBox = tr.insertCell(tdi++);
			this.hTime.setParent(this.hBox);
			this.mTime.setParent(this.mBox);
			this.sTime.setParent(this.sBox);
			var ctstr = tr.insertCell(tdi++);
			this._setHtml(ctstr, this.getI18n("qzz.current", '当前'), false);
			ctstr.style.padding = "3px";
			ctstr.style.cursor = "pointer";
			ctstr.date = this;
			ctstr.onclick = function() {
				var me = this.date;
				var ct = me._getCurTime();
				me.hTime.setValue(ct.h);
				me.mTime.setValue(ct.m);
				me.sTime.setValue(ct.s);
			}
			this.setStyle(ctstr, "weekCommonCell");
			var hmsH = 0;
			if(this.cyctype === this.cyctypes.day && this.showTime) {
				this.timeRow.style.display = "";
				hmsH = 32;
			} else {
				hmsH = 0;
				this.timeRow.style.display = "none";
			}
			//当天选择区
			var row4 = this.thisWindow.insertRow(3);
			this.footerBox = row4.insertCell(0);
			this._addCssList(this.footerBox, "dateCell");
			sh += 30;
			//渲染选择窗口.
			this.refreshCalendar();
			row1 = null;    
			row2 = null;
			row3 = null;
	        this.setHeight(sh + hmsH);
	        this._sumHeight = sh;
	        this.setWidth(this.getOption().width);	        
		},
		/**
		 * 添加dom列表.
		 */
		_addCssList:function(el, className) {
			this.setStyle(el, className);
			if(this.isEmpty(el.id)) {
				el.id = "Calendar" + this.domIndex;
				this.domIndex++;
			}
			this.domList[el.id] = {"dom":el,"className":className};
		},
		/**
		 * 设置样式前辍.
		 */
		_setCssPrefix:function(cssPrefix) {
			 if(this._cssPrefix !== cssPrefix) {
				this._cssPrefix = cssPrefix;
				for(var key in this.domList) {
					var item = this.domList[key];
					this.setStyle(item.dom, item.className);
				}
			}
		},
		_refreshHeader:function() {			
			if(this.selYear == null) {
				this.selYear = this.curYear;
			}
			if(this.selMonth == null) {
				this.selMonth = this.curMonth;
			}
			if(this.selDay == null) {
				this.selDay = this.curDay;
			}
			switch(this.curCyctype) {
			case this.cyctypes.hour:
				    this._setHtml(this.headText, this.curYear + this.getI18n("qzz.year", "年") 
				    		                                  + this.monthCN[this.curMonth - 1] 
				                                              + this.curDay + this.getI18n("qzz.day", "日"));
				    break;
			case this.cyctypes.day:
					this._setHtml(this.headText, this.curYear + this.getI18n("qzz.year", "年") + this.monthCN[this.curMonth - 1]);
					break;
			case this.cyctypes.month:
					this._setHtml(this.headText, this.curYear + this.getI18n("qzz.year", "年"));
					break;
			case this.cyctypes.season:
					this._setHtml(this.headText, this.curYear + this.getI18n("qzz.year", "年"));
					break;
			case this.cyctypes.year:
					var startYear = this.selYear;
					startYear = startYear/10;
					//取整
					isy = parseInt(startYear, 10);
					//判断是否相等
					if(startYear - isy === 0) {
						isy = isy - 1;
					}
					//重新还原值
					startYear = isy * 10 + 1;				
					this._setHtml(this.headText, startYear + this.getI18n("qzz.year", "年") + "-" + (startYear+9) + this.getI18n("qzz.year", "年"));
					break;
			}
		},
		/**
		 * 日期控件头部份初始化.
		 */
		_getHeaderBox:function() {
			//top box
			var mTitle = this.createElement("table");
			this._addCssList(mTitle, "weekDay");
			mTitle.border = 0;
			mTitle.cellPadding = 0;
			mTitle.cellSpacing = 0;
			var trow = mTitle.insertRow(0);
			var k = 0;
			//prior month
			var tcol1 = trow.insertCell(k++);	
			tcol1.style.width = "20px";
			this._addCssList(tcol1, "weekCommonCell");
			var priorDiv = this.createElement("div");
			this._addCssList(priorDiv, "priorMonthCell");
			this._setHtml(priorDiv, "&lt;");
			tcol1.appendChild(priorDiv);
			tcol1.onclick = this.doDecClick;
			//主输出区
			var headBox = trow.insertCell(k++);			
			this.headInfo = this.createElement("table");			
			this.setStyle(this.headInfo, "weekDay");			
			this.headText = this.headInfo.insertRow(0).insertCell(0);
			this.headText.date = this;
			this.headText.onclick = function() {
				switch(this.date.curCyctype) {
					case this.date.cyctypes.second:
						this.date.curCyctype = this.date.cyctypes.minute;
						break;
					case this.date.cyctypes.minute:
						this.date.curCyctype = this.date.cyctypes.hour;
						break;
					case this.date.cyctypes.hour:
						this.date.curCyctype = this.date.cyctypes.day;
						break;
					case this.date.cyctypes.day:
			            this.date.curCyctype = this.date.cyctypes.month;
			            break;
					case this.date.cyctypes.month:
						this.date.curCyctype = this.date.cyctypes.year;
						break;
					case this.date.cyctypes.season:
						this.date.curCyctype = this.date.cyctypes.year;
						break;
				}
				this.date.refreshCalendar();
			};
			this.headInfo.style.width ="100%";			
			this.headInfo.style.height = "100%";	
			this._refreshHeader();
			this.setStyle(this.headText, "weekCommonCell");
			headBox.appendChild(this.headInfo);
			
			//next month
			var tcol4 = trow.insertCell(k++);
			var nextDiv = this.createElement("div");
			this._addCssList(nextDiv, "nextMonthCell");
			this._setHtml(nextDiv, "&gt;");
			tcol4.appendChild(nextDiv);
			tcol4.style.width = "20px";
			tcol4.onclick = this.doAddClick;
			this._addCssList(tcol4, "weekCommonCell");
			tcol1.date = this;	
			tcol4.date = this;
			
			trow = null;
			tcol1 = null;            
			tcol2 = null;
			tselyear = null;
			return mTitle;
		},
		/**
		 * 刷新选择footer部份.
		 */
		_refreshFooter:function() {
			this.footerBox.today = 1;
			switch(this.cyctype) {
				case this.cyctypes.year:
					this._setHtml(this.footerBox, this.toYear, false);
					this.footerBox.onclick = this.doToyearSelect;	
					break;
				case this.cyctypes.season:
					this.footerBox.year = this.toYear;
					this.footerBox.season = this.dateObj.getSeasonByMonth(this.toMonth)
					this._setHtml(this.footerBox, this.toYear + this.getI18n("qzz.year", "年") + " " + this.seasonCN[this.footerBox.season - 1], false);
					this.footerBox.onclick = this.doToseasonSelect;
					break;
				case this.cyctypes.month:
					this._setHtml(this.footerBox, this.toYear + this.dateSplit + this.toMonth, false);					
					this.footerBox.onclick = this.doTomonthSelect;	
					break;
				case this.cyctypes.day:
					this._setHtml(this.footerBox, this.toYear + this.dateSplit + this.toMonth + this.dateSplit + this.toDay, false);					
					this.footerBox.onclick = this.doTodaySelect;	
					break;
				case this.cyctypes.hour:
					this._setHtml(this.footerBox, 
							this.toYear + this.dateSplit + this.toMonth + this.dateSplit + this.toDay 
							+ " " + this.toHour + ":00:00", 
							false);					
					this.footerBox.onclick = this.doTotimeSelect;
					break;
				case this.cyctypes.minute:
					var date = new Date();
					var hs = date.getHours();
					var ms = date.getMinutes();
					if(typeof ms == "number" && ms < 10 || typeof ms == "string" && ms.length == 0) {
						ms = "0" + ms;
					}
					this._setHtml(this.footerBox, 
							this.toYear + this.dateSplit + this.toMonth + this.dateSplit + this.toDay 
							    + " " + hs + ":" + ms + ":00",
							false);					
					this.footerBox.onclick = this.doTotimeSelect;
					var me = this;
					this._asynRun(function(){
						me._refreshFooter();
						me = null;
					}, 30000);
					break;
				case this.cyctypes.second:
					var date = new Date();
					var hs = date.getHours();
					var ms = date.getMinutes();
					var ss = date.getSeconds();
					if(typeof ms == "number" && ms < 10 || typeof ms == "string" && ms.length == 0) {
						ms = "0" + ms;
					}
					
					if(typeof ss == "number" && ss < 10 || typeof ss == "string" && ss.length == 0) {
						ss = "0" + ss;
					}
					this._setHtml(this.footerBox, 
							this.toYear + this.dateSplit + this.toMonth + this.dateSplit + this.toDay 
							    + " " + hs + ":" + ms + ":" + ss, 
							false);					
					this.footerBox.onclick = this.doTotimeSelect;
					var me = this;
					this._asynRun(function(){
						me._refreshFooter();
						me = null;
					}, 500);
					break;
			}
			if(this.isReadOnly(this.toYear, this.toMonth, this.toDay, this.cyctype)) {
				this.setStyle(this.footerBox, "weekReadOnlyCell");
				this.footerBox.onclick = "";
			} else {
				this.setStyle(this.footerBox, "weekCommonCell");	
			}		
			this.addStyle(this.footerBox, "toDaySel");
			this.footerBox.style.paddingLeft = "4px";
			this.footerBox.date = this;			
		},
		/**
		* 生成日期面板.
		*/
		_getDayBox:function() {
			//center box
			mBox = this.createElement("table");					
			mBox.border = 0;
			mBox.cellPadding = 0;
			mBox.cellSpacing = 0;
			
			var mT = mBox.insertRow(0).insertCell(0);
			//week's title
			mTitleDay = this.createElement("table");					
			this._addCssList(mTitleDay, "weekTitle");					
			var weekRow = mTitleDay.insertRow(0);					
			for (var i = 0; i < 7; i++) {
			    var wcol = weekRow.insertCell(i);
			    this._setHtml(wcol, this.weeks[i], false);
			    if (i == 0) {
			        this._addCssList(wcol, "weekSunTitle");
			    } else if (i == 6) {
			    	this._addCssList(wcol, "weekSixTitle");
			    } else {
			    	this._addCssList(wcol, "weekCommonTitle");
			    }
			    wcol = null;
			}					
			mT.appendChild(mTitleDay);
			mT = null;
			//date box
			var mD = mBox.insertRow(1).insertCell(0);				
			
			//处理日期面板
			this.selYear = this.curYear;
			this.selMonth = this.curMonth;
			//this.selDay = this.curDay;
			this._refreshHeader();
				
			//var firstDate = new Date(this.curYear, this.curMonth - 1, 1);
			//var curWeek = firstDate.getDay();
					
			var dayIndex = 1;
			var hasInit = false;
			
			mDay = this.createElement("table");					
			this._addCssList(mDay, "weekDay");
			mDay.cellSpacing = 3;
			//var mdays = this.getMonthDays(this.curYear, this.curMonth);
			var drect = this.dateObj.getDaysRect(this.curYear, this.curMonth, true);
			
			var pm = this.curMonth - 1;
			var py = this.curYear;
			if(pm < 1) {
				pm = 12;
				py--;
			}
			//日期区刷新
			for (var i = 0, rlen = drect.length; i < 6; i++) {
			    var wrow = mDay.insertRow(i);
			    if(i < rlen) {
			    	if(wrow.style.display == "none") {
			    		wrow.style.display = "";
			    	}
				    for ( j = 0; j < 7; j++) {
				        var ccol = wrow.insertCell(j);
				        var di = drect[i][j];
				        if(di == 1) {
				        	pm ++;
				        	if(pm > 12) {
				        		py++;
				        		pm = 1;
				        	}
				        }
				        //刷新单元格.
				        this._refreshDayCell(ccol, j, di, py, pm);
				        ccol = null;
				    } //j
			    } else {
			    	wrow.style.display = "none";
			    }
			    wrow = null;
			} //i
			mD.appendChild(mDay);
			this.dayTable = mDay;
			tab = null;		
			firstDate = null;			
			mD = null;
			weekRow = null;
			return mBox;
		},
		/**
		* 刷新日期面板.
		*/
		_refreshDayBox:function() {
			//debugger;
			//处理日期面板
			this.selYear = this.curYear;
			this.selMonth = this.curMonth;
			this._refreshHeader();
			var drect = this.dateObj.getDaysRect(this.curYear, this.curMonth, true);
			var pm = this.curMonth - 1;
			var py = this.curYear;
			if(pm < 1) {
				pm = 12;
				py--;
			}
			//日期区刷新
			var tab = this.dayTable;
			for (var i = 0, rlen = drect.length; i < 6; i++) {
			    var wrow = tab.rows[i];
			    if(i < rlen) {
			    	if(wrow.style.display == "none") {
			    		wrow.style.display = "";
			    	}
				    for ( j = 0; j < 7; j++) {
				        var ccol = wrow.cells[j];
				        var di = drect[i][j];
				        if(di == 1) {
				        	pm ++;
				        	if(pm > 12) {
				        		py++;
				        		pm = 1;
				        	}
				        }
				        //刷新单元格.
				        var re = this._refreshDayCell(ccol, j, di, py, pm);
				        ccol = null;
				    } //j
			    } else {
			    	wrow.style.display = "none";
			    }
			    wrow = null;
			} //i
			tab = null;		
			firstDate = null;
		},		 
		/**
		* 刷新单个日期格.
		*/
		_refreshDayCell:function(ccol, colIndex, dayIndex, cy, cm) {
			ccol.date = this;
			ccol.align = "right";
			this._setHtml(ccol, "", false);
			ccol.bgColor = "";
			ccol.onclick = "";
			ccol.onmouseover = "";
			ccol.onmouseout = "";
			ccol.tmpClassName = "";
			if (colIndex == 0) {
				this.setStyle(ccol, "weekSunCell");
			} else if (colIndex == 6) {
				this.setStyle(ccol, "weekSixCell");
			} else {
				this.setStyle(ccol, "weekCommonCell");
			}
			//不为空的时候
			if(dayIndex != null) {
				this._setHtml(ccol, dayIndex, false);
				ccol.onclick = this.doSelect;
				ccol.year = cy;
				ccol.month = cm;
				ccol.day = dayIndex;
			}	
			if(cm != this.curMonth) {
				this.setStyle(ccol, "otherWeekCommonCell");
			}
			if (cy == this.toYear && this.toMonth == cm && dayIndex == this.toDay) {
			    this.setStyle(ccol, "weekToDayCell");
			}			
			if (cy == this.curYear && this.curMonth == cm && this.curDay != undefined && dayIndex == this.curDay) {
			    this.setStyle(ccol, "weekSelCell");
			}			
			if(ccol.innerHTML !== "" && this.isReadOnly(this.curYear, cm, parseInt(ccol.innerHTML, 10), this.cyctypes.day)) {
				this.setStyle(ccol, "weekReadOnlyCell");
				ccol.onclick = "";
			}
		},
		/**
		 * 获得主表区域内容.
		 */
		_getMainBox:function(rect, stateFunc) {
			var box = this.createElement("table");
			this.setStyle(box, "mainBox");
			for(var i = 0, rlen = rect.length; i < rlen; i++) {
				var row = rect[i];
				var hrow = box.insertRow(i);
				for(var j = 0, clen = row.length; j < clen; j++) {
					cell = row[j];
					hcell = hrow.insertCell(j);
					hcell.date = this;
					hcell.onclick = this.doSelect;
					this._setHtml(hcell, cell);
					var state = 0;
					if(typeof stateFunc == "function") {
						state = stateFunc.apply(this, [cell, hcell, i, j, rlen, clen]);
					}
					switch(state) {
						case "other":
							this.setStyle(hcell, "otherWeekCommonCell");break;
						case "select":
							this.setStyle(hcell, "weekSelCell");break;
						case "readonly":
							this.setStyle(hcell, "weekReadOnlyCell");break;
						case "current":
							this.setStyle(hcell, "weekToDayCell");break;
						default:
							this.setStyle(hcell, "weekCommonCell");break;
					}
				}
			}
			return box;
		},
		/**
		 * 刷新主表区域内容.
		 */
		_refreshMainBox:function(box, rect, stateFunc, cellFunc) {
			var hrect = rect;
			var hBox = box;
			for(var i = 0, rlen = hrect.length; i < rlen; i++) {
				var row = hrect[i];
				var hrow = hBox.rows[i];
				for(var j = 0, clen = row.length; j < clen; j++) {
					cell = row[j];
					hcell = hrow.cells[j];
					hcell.onclick = this.doSelect;
					this._setHtml(hcell, cell);
				    var state = 0;
					if(typeof stateFunc == "function") {
						state = stateFunc.apply(this, [cell, hcell, i, j, rlen, clen]);
					}
					switch(state) {
						case "other":
							this.setStyle(hcell, "otherWeekCommonCell");break;
						case "select":
							this.setStyle(hcell, "weekSelCell");break;
						case "readonly":
							this.setStyle(hcell, "weekReadOnlyCell");break;
						case "current":
							this.setStyle(hcell, "weekToDayCell");break;
						default:
							this.setStyle(hcell, "weekCommonCell");break;
					}
					if(typeof cellFunc == "function") {
						cellFunc(hcell);
					}
					
				}
			}			
		},
		/**
		 * 年从状态函数.
		 * @param value 值
		 * @param cell 单元格
		 * @param i 序号
		 */
		_yearState:function(value, cell, i, j, rlen, clen) {
			cell.isOther = null;
			if(value > this.maxYear || value < this.minYear){
				return "readonly";
			} else if(i == 0 && j == 0 || i == rlen - 1 && j == clen - 1) {
				if(i == 0) {
					cell.isOther = "prior";
				} else {
					cell.isOther = "next";
				}
				return "other";
			} else if(value == this.curYear) {
				return "select";						
			} else if(value == this.toYear) {
				return "current";			
			}
		},
		/**
		 * 刷新年份选择窗口.
		 */
		_refreshYearBox:function() {
			var yrect = this.dateObj.getYearsRect(this.curYear);
			var me = this;
			this._refreshMainBox(this.yearTable, yrect, this._yearState, function(hcell) {
				if(hcell.innerHTML !== "" && me.isReadOnly(parseInt(hcell.innerHTML, 10), 1, 1, me.cyctypes.year)) {
					me.setStyle(hcell, "weekReadOnlyCell");
					hcell.onclick = "";
				}				
			});
		},
		/**
		 * 获取年份窗口.
		 */
		_getYearBox:function() {
			var yrect = this.dateObj.getYearsRect(this.curYear);
			this.yearTable = this._getMainBox(yrect, this._yearState);			
			this.yearTable.style.height = "182px";
			this.yearTable.style.width = "190px";
			return this.yearTable;	
		},
		_seasonState:function(value, cell, i, j, rlen, clen) {
			var k = i * clen + j + 1;
			cell.season = k;
			var month = this.dateObj.getMonthBySeason(k);
			var curSeason = this.dateObj.getSeasonByMonth(this.curMonth);
			if(this.isReadOnly(this.curYear, month, 1, this.cyctypes.month)) {
				return "readonly";
			} else if(k === curSeason) {
				return "select";
			} else if(this.curYear == this.toYear 
					&& k === this.dateObj.getSeasonByMonth(this.toMonth)) {
				return "current";
			}
		},
		/**
		 * 获取季度窗口.
		 */
		_getSeasonBox:function() {
	        var seasonRect = this.dateObj.getSeasonsRect();
	        this.seasonTable = this._getMainBox(seasonRect, this._seasonState);
	        this.seasonTable.style.height = "104px";
			this.seasonTable.style.width = "190px";
			return this.seasonTable;	
        },
        /**
         * 刷新季度面板.
         */
        _refreshSeasonBox:function() {
        	this._refreshHeader();
			var me = this;
			this._refreshMainBox(this.seasonTable, this.dateObj.getSeasonsRect(), this._seasonState, 
			    function(hcell) {
				    if(hcell.innerHTML !== "" && me.isReadOnly(me.curYear, me.dateObj.getMonthBySeason(hcell.season), 1, me.cyctypes.month)) {
					    me.setStyle(hcell, "weekReadOnlyCell");
					    hcell.onclick = "";
				    }
			    });
        },
		_monthState:function(value, cell, i, j, rlen, clen) {
			var k = i * clen + j + 1;
			cell.month = k;
			if(this.isReadOnly(this.curYear, k, 1, this.cyctypes.month)) {
				return "readonly";
			} else if(k === this.curMonth) {
				return "select";
			} else if(this.curYear == this.toYear && k === this.toMonth) {
				return "current";
			}
		},
		/**
		* 生成月份面板.
		*/
		_getMonthBox:function() {
			var mBox = this._getMainBox(this.dateObj.getMonthsRect(), this._monthState);			
			mBox.style.height = "182px";
			mBox.style.width = "190px";
			this.monthTable = mBox;
			return mBox;						
		},
		/**
		 * 刷新月选择框.
		 */
		_refreshMonthBox:function() {
			this._refreshHeader();
			var me = this;
			this._refreshMainBox(this.monthTable, this.dateObj.getMonthsRect(), this._monthState, 
			    function(hcell) {
				    if(hcell.innerHTML !== "" && me.isReadOnly(me.curYear, parseInt(hcell.innerHTML, 10), 1, me.cyctypes.month)) {
					    me.setStyle(hcell, "weekReadOnlyCell");
					    hcell.onclick = "";
				    }
			    });
		},
		_hourState:function(value, cell, i, j, rlen, clen) {
			var k = i * clen + j;
			cell.hour = k;
			if(k === this.curHour) {
				return "select";
			}
		},
		/**
		 * 返回小时选择窗口.
		 */
		_getHourBox:function() {
			var hrect = this.dateObj.getHoursRect();
			this.hourTable = this._getMainBox(hrect, this._hourState);
			return this.hourTable;			
		},
		/**
		 * 刷新年份选择窗口.
		 */
		_refreshHourBox:function() {
			var hrect = this.dateObj.getHoursRect();
			this._refreshMainBox(this.hourTable, hrect, this._hourState);
			return this.hourTable;	
		},
		/**
		 * 分钟面板刷新.
		 */
		_minuteState:function(value, cell, i, j, rlen, clen) {
			var k = value.split(":");
			k = parseInt(k[1], 10);
			cell.minute = parseInt(k, 10);
			if(k == this.curMinute) {
				return "select";
			}
		},
		/**
		 * 获取分钟面板.
		 */
		_getMinuteBox:function() {
			var mrect = this.dateObj.getMinutesRect(this.curHour);
			this.minuteTable = this._getMainBox(mrect, this._minuteState);
			return this.minuteTable;
		},
		_refreshMinuteBox:function() {
			var mrect = this.dateObj.getMinutesRect(this.curHour);
			this._refreshMainBox(this.minuteTable, mrect, this._minuteState);
			return this.minuteTable;
		},
		/**
		 * 分钟面板刷新.
		 */
		_secondState:function(value, cell, i, j, rlen, clen) {
			var k = value.split(":");
			k = parseInt(k[2], 10);
			cell.second = k;
			if(k == this.curSecond) {
				return "select";
			}
		},
		/**
		 * 获取分钟面板.
		 */
		_getSecondBox:function() {
			var srect = this.dateObj.getSecondsRect(this.curHour, this.curMinute);
			this.secondTable = this._getMainBox(srect, this._secondState);
			return this.secondTable;
		},
		_refreshSecondBox:function() {
			var srect = this.dateObj.getSecondsRect(this.curHour, this.curMinute);
			this._refreshMainBox(this.secondTable, srect, this._secondState);
			return this.secondTable;
		},
		/**
		 * 是否润年.
		 * @param inYear 年
		 */
	    isLeapYear:function(inYear) {
	    	return this.dateObj.isLeapYear(inYear);
		},		
		/**
		 * 获取某月天数.
		 * @param year 年
		 * @param month 月
		 * @return 返回
		 */
	    getMonthDays:function(year, month) {
	    	return this.dateObj.getMonthDays(year, month);
	    },
	    /**
	     * 处理超出最大最小值.
	     */
	    checkRound:function(date) {
	    	var split = this.dateSplit;
	    	var dAry = date.split(split);
	    	var state = "none";	    	
	    	year = parseInt(dAry[0], 10);
	    	month = parseInt(dAry[1], 10);
	    	day = parseInt(dAry[2], 10);
	    	if(year > this.maxYear) {
	    		year = this.maxYear;
	    		month = this.maxMonth;
	    		day = this.maxDay;
	    		state = "max";
	    	} else if(year == this.maxYear && month > this.maxMonth) {
	    		month = this.maxMonth;
	    		day = this.maxDay;
	    		state = "max";
	    	} else if(year == this.maxYear && month == this.maxMonth 
	    			&& day > this.maxDay && this.cyctype==this.cyctypes.day) {
	    		day = this.maxDay;
	    		state = "max";
	    	}
	    	if(year < this.minYear) {
	    		year = this.minYear;
	    		month = this.minMonth;
	    		day = this.minDay;
	    		state = "min";
	    	} else if(year == this.minYear && month < this.minMonth) {
	    		month = this.minMonth;
	    		day = this.minDay;
	    		state = "min";
	    	} else if(year == this.minYear && month == this.minMonth 
	    			&& day < this.minDay && this.cyctype==this.cyctypes.day) {
	    		day = this.minDay;
	    		state = "min";
	    	}
            return {"state":state,"date":this._dateToStr(year, month, day)};
	    },
	    /**
		 * 日期转换成字符串.
		 */
	    _dateToStr:function(year, month, day) {
	    	return this.dateObj._dateToStr(year, month, day);
	    },
			    
	    /**
	     * 日期合法性检查.
	     * @param date 日期
	     */
	    checkDate:function(date){
	    	return this.dateObj.checkDate(date);
	    },
	    /**
	     * 转换到日期.
	     * @param value 日期.
	     */
	    toDate:function(value) {
	    	return this.toDate(value);	    	
	    },
	    /**
	     * 获取下一日期.
	     * @param date 日期
	     */
	    getNextDate:function(date) {
	    	var date = this.checkDate(date);
	    	if(date !== "") {
	    		var dateAry = date.split(this.dtSplit);
	    		var year = parseInt(dateAry[0], 10);
	    		var month = parseInt(dateAry[1], 10);
	    		var day = parseInt(dateAry[2], 10);
	    		var maxDay = this.getMonthDays(year, month);
	    		if(day < maxDay) {
	    			day ++;
	    		} else {
	    			day = 1;
	    			if(month < 12) {
	    				month ++;
	    			} else {
	    				month = 1;
	    				year ++;
	    			}
	    		}
	    		var re = year + this.dateSplit + month + this.dateSplit + day;
	    		if(dateAry.length > 3) {
	    			re = re + " " + dateAry[3];
	    		}
	    		return re;
	    	}
	    },
	    /**
	     * 上一日期.
	     * @param date 日期.
	     */
	    getPriorDate:function(date) {
	    	var date = this.checkDate(date);
	    	if(date !== "") {
	    		var dateAry = date.split(this.dtSplit);
	    		var year = parseInt(dateAry[0], 10);
	    		var month = parseInt(dateAry[1], 10);
	    		var day = parseInt(dateAry[2], 10);
	    		var maxDay = this.getMonthDays(year, month - 1);
	    		if(day > 1) {
	    			day --;
	    		} else {
	    			day = 12;
	    			if(month > 1) {
	    				month --;
	    			} else {
	    				month = 12;
	    				year --;
	    			}
	    		}
	    		var re = year + this.dateSplit + month + this.dateSplit + day;
	    		if(dateAry.length > 3) {
	    			re = re + " " + dateAry[3];
	    		}
	    		return re;
	    	}
	    },
	    /**
	     * 执行月减少选择.
	     */
	    doDecClick:function() {
	    	if(this.date.curCyctype === this.date.cyctypes.hour) {
	    		if(this.date.curDay > 1) {
	    			this.date.curDay--
	    		} else {
	    			if(this.date.curMonth > 1) {
	    			    this.date.curMonth--;
	    			} else {
	    				this.date.curYear--;
	    				this.date.curMonth = 12;
	    			}
	    			this.date.curDay = this.date.getMonthDays(this.date.curYear, this.date.curMonth);
	    		}
	    	} else if(this.date.curCyctype === this.date.cyctypes.day) {
	    		if(this.date.selMonth > 1) {
	    			this.date.selMonth --;
		        } else {
		        	this.date.selYear--;
		        	this.date.selMonth = 12;
		        	this.date.curYear = this.date.selYear;
		        }
		        this.date.curMonth = this.date.selMonth; 
	        } else if(this.date.curCyctype === this.date.cyctypes.month || this.date.curCyctype === this.date.cyctypes.season) {
	        	this.date.selYear--;
	        	this.date.curYear = this.date.selYear;
	        } else if(this.date.curCyctype === this.date.cyctypes.year) {
				this.date.selYear=this.date.selYear - 10;
				this.date.curYear = this.date.selYear;
			}	  
	        this.date.refreshCalendar();
	    },
	    /**
	     * 执行月增加选择.
	     */
	    doAddClick:function() {
	    	if(this.date.curCyctype === this.date.cyctypes.hour) {
	    		var cd = this.date.getMonthDays(this.date.curYear, this.date.curMonth);
	    		if(this.date.curDay < cd) {
	    			this.date.curDay++;
	    		} else {
	    			if(this.date.curMonth < 12) {
	    				this.date.curMonth++;
	    			} else {
	    				this.date.curYear++;
	    				this.date.curMonth = 1;
	    			}
	    			this.date.curDay = 1;
	    		}
	    	} else if(this.date.curCyctype === this.date.cyctypes.day) {
	    		if(this.date.selMonth < 12) {
				    this.date.selMonth++;
				} else {
					this.date.selYear++;
					this.date.selMonth = 1;
					this.date.curYear = this.date.selYear;
				}
				this.date.curMonth = this.date.selMonth;
			} else if(this.date.curCyctype === this.date.cyctypes.month || this.date.curCyctype === this.date.cyctypes.season){
				this.date.selYear++;
				this.date.curYear = this.date.selYear;
			} else if(this.date.curCyctype === this.date.cyctypes.year) {				
				this.date.selYear= this.date.selYear + 10;
				this.date.curYear = this.date.selYear;
			}		
	    	
			this.date.refreshCalendar();
		},
		/**
		 * 执行选择.
		 */
	    doSelect:function() {
	        if (this.date.priorSel != null) {
	            this.date.priorSel.bgColor = "";
	        }
	        this.date.priorSel = this;
	        var pCyctype = this.date.curCyctype;
	        switch(this.date.curCyctype) {
		        case this.date.cyctypes.second:
		        	    this.date.curSecond = this.second;
		        	    break;
		        case this.date.cyctypes.minute:
		                this.date.curMinute = this.minute;
		                if(this.date.cyctype !== this.date.cyctypes.year 
			            		&& this.date.cyctype !== this.date.cyctypes.month
			            		    && this.date.cyctype !== this.date.cyctypes.day
			            		        && this.date.cyctype !== this.date.cyctypes.hour
			            		            &&  this.date.cyctype !== this.date.cyctypes.minute) {
			            	this.date.curCyctype = this.date.cyctypes.second;
			            }
		        	    break;
		        case this.date.cyctypes.hour:
		        	    this.date.curHour = this.hour;
		        	    if(this.date.cyctype !== this.date.cyctypes.year 
			            		&& this.date.cyctype !== this.date.cyctypes.month
			            		    && this.date.cyctype !== this.date.cyctypes.day
			            		        && this.date.cyctype !== this.date.cyctypes.hour) {
			            	this.date.curCyctype = this.date.cyctypes.minute;
			            }
		        	    break;
		        case this.date.cyctypes.day:
				        this.date.curMonth = this.month;
			            this.date.curYear = this.year;
			            if (this.innerHTML != undefined) {
			                this.date.curDay = parseInt(this.innerHTML, 10);
			            }
			            if(this.date.cyctype !== this.date.cyctypes.year 
			            		&& this.date.cyctype !== this.date.cyctypes.month
			            		    && this.date.cyctype !== this.date.cyctypes.day) {
			            	this.date.curCyctype = this.date.cyctypes.hour;
			            }
			            break;
		        case this.date.cyctypes.month:
			            //处理月份
			        	this.date.curMonth = this.month;	        	
			        	if(this.date.cyctype !== this.date.cyctypes.year && this.date.cyctype !== this.date.cyctypes.month) {
			        		this.date.curCyctype = this.date.cyctypes.day;
			        	} else {
			        		this.date.curDay = 1;
			        	}
			        	break;
		        case this.date.cyctypes.season:
		        	    this.date.curMonth = this.date.dateObj.getMonthBySeason(this.season);
		        	    this.date.curDay = 1;
		                break;
		        case this.date.cyctypes.year:
			        	this.date.curYear = parseInt(this.innerHTML, 10);
			        	if(this.isOther == "next") {
			        		this.date.selYear = this.date.selYear + 10;
			        	} else if(this.isOther == "prior") {
			        		this.date.selYear = this.date.selYear - 10;
			        	}
			        	if(this.date.cyctype !== this.date.cyctypes.year) {
			        		if(this.date.cyctype == this.date.cyctypes.season) {
			        			this.date.curCyctype = this.date.cyctypes.season;
			        		} else {			        		
			        		    this.date.curCyctype = this.date.cyctypes.month;
			        		}
			        	} else {
				        	this.date.curMonth = 1;
				        	this.date.curDay = 1;	        		
			        	}
			        	break;
	        }
	        this.date.refreshCalendar();
	        if(pCyctype === this.date.cyctype && typeof this.date.onSelect == "function") {
	        	this.date.onSelect(this.date);
	        }
	    },
	    doTotimeSelect:function() {
	    	if(this.date.cyctype == this.date.cyctypes.hour 
	    			|| this.date.cyctype == this.date.cyctypes.minute
	    			    || this.date.cyctype == this.date.cyctypes.second) {
	    		if(this.innerHTML != null) {
	    			var ds = this.date._decodeDateTime(this.innerHTML);
	    			this.date.curYear = ds.year;
	    			this.date.curMonth = ds.month;
	    			this.date.curDay = ds.day;
	    			this.date.curHour = ds.hour;
	    			this.date.curMinute = ds.minute;
	    			this.date.curSecond = ds.second;
	    		}
	    	}
	    	if(typeof this.date.onSelect == "function") {
	        	this.date.onSelect(this.date);
	        }
	    },
	    /**
	     * 执行选择今天.
	     */
	    doTodaySelect:function() {
			if (this.date.cyctype == this.date.cyctypes.day) {			
			    if (this.innerHTML != undefined) {
			    	var ds = this.date._decodeDateTime(this.innerHTML);
			        this.date.curYear = ds.year;
			        this.date.curMonth = ds.month;
			        this.date.curDay = ds.day;      
			    }
			}
			if(typeof this.date.onSelect == "function") {
	        	this.date.onSelect(this.date);
	        }
		},
		/**
		 * 执行选择今天.
		 */
		doTomonthSelect:function() {
			if (this.date.cyctype == this.date.cyctypes.month) {			
			    if (this.innerHTML != undefined) {
			    	var ds = this.date._decodeDateTime(this.innerHTML);
			        this.date.curYear = ds.year;
			        this.date.curMonth = ds.month;
			        this.date.curDay = 1;	        
			    }
			}
			if(typeof this.date.onSelect == "function") {
	        	this.date.onSelect(this.date);
	        }
		},
		doToyearSelect:function() {
			if (this.date.cyctype == this.date.cyctypes.year) {			
			    if (this.innerHTML != undefined) {
			        this.date.curYear = parseInt(this.innerHTML, 10);
			        this.date.curMonth = 1;
			        this.date.curDay = 1;	        
			    }
			}
			if(typeof this.date.onSelect == "function") {
	        	this.date.onSelect(this.date);
	        }
		},
		/**
		 * 选择当季. 暂时不需要.
		 */
		doToseasonSelect:function() {
			if(this.date.cyctype == this.date.cyctypes.season) {
				if(this.innerHTML != null) {
					this.date.curYear = this.year;
					this.date.curMonth = this.date.dateObj.getMonthBySeason(this.season);
					this.date.curDay = 1;
				}
			}
			if(typeof this.date.onSelect == "function") {
	        	this.date.onSelect(this.date);
	        }
		},
	    /**
	     * 判断是否只读.
	     * @param curYear 年
	     * @param curMonth 月
	     * @param curDay 日
	     * @return 返回
	     */
		isReadOnly : function(curYear, curMonth, curDay, cyctype) {
	    	 var res = true;
	    	 if(cyctype == null) {
	    		 cyctype = this.cyctypes.day;
	    	 }
	    	 switch(cyctype) {
	    	 case this.cyctypes.year:	    	 
	    		  res = curYear > this.maxYear || curYear < this.minYear;
	    		  break;
	    	 case this.cyctypes.season:
	    		  res = curYear > this.maxYear 
					     || curYear < this.minYear 
			    		    || curYear == this.maxYear && curMonth > this.maxMonth 
			    		        || curYear == this.minYear && curMonth < this.minMonth;
			      break;
	    	 case this.cyctypes.month:
	    		  res = curYear > this.maxYear 
					     || curYear < this.minYear 
			    		    || curYear == this.maxYear && curMonth > this.maxMonth 
			    		        || curYear == this.minYear && curMonth < this.minMonth;
	    	 case this.cyctypes.day:
	    		  res = curYear > this.maxYear 
				     || curYear < this.minYear 
		    		    || curYear == this.maxYear && curMonth > this.maxMonth 
		    		        || curYear == this.minYear && curMonth < this.minMonth
		    		            || (curYear == this.maxYear && curMonth == this.maxMonth && curDay > this.maxDay
		    		                || curYear == this.minYear && curMonth == this.minMonth && curDay < this.minDay);
		    	  break;
	    	 }
	    	 return res;
		},
		/**
		 * 刷新时间面板.
		 * @param isFirst 首次状态
		 */
		refreshCalendar : function(isFirst) {	
			//生成表头.
		    if(this.isEmpty(this.headerTable)) {
		    	this.headerTable = this._getHeaderBox();
		    	this.headBox.align = "center";
				this.headBox.appendChild(this.headerTable);
		    } else {
		    	this._refreshHeader();
		    }
		    //body
			switch(this.curCyctype) {
				case this.cyctypes.year : 
					if(this.isEmpty(this.yearBox) || this.yearBox.rows.length == 0) {
						this._setHtml(this.bodyBox, "", false);
						this.yearBox = this._getYearBox();
						this.bodyBox.appendChild(this.yearBox);
					} else {
						if(this.bodyBox.childNodes.length == 0 
								|| this.bodyBox.childNodes[0] !== this.yearBox) {
							this._setHtml(this.bodyBox, "", false);
				    	    this.bodyBox.appendChild(this.yearBox);							
						}
						this._refreshYearBox();
					}
					break;
				case this.cyctypes.season : 
					if(this.isEmpty(this.seasonBox) || this.seasonBox.rows.length == 0) {
						this._setHtml(this.bodyBox, "", false);
						this.seasonBox = this._getSeasonBox();
						this.bodyBox.appendChild(this.seasonBox);
					} else {
						if(this.bodyBox.childNodes.length === 0 
				    			|| this.bodyBox.childNodes[0] !== this.seasonBox) {
				    		this._setHtml(this.bodyBox, "", false);
				    	    this.bodyBox.appendChild(this.seasonBox);
				    	}
						this._refreshSeasonBox();
					}
				    break;
				case this.cyctypes.month : 
				    //月份选择
					if(this.isEmpty(this.monthBox) || this.monthBox.rows.length == 0) {
						this._setHtml(this.bodyBox, "", false);
				        this.monthBox = this._getMonthBox();
				        this.bodyBox.appendChild(this.monthBox);
				    } else {
				    	if(this.bodyBox.childNodes.length === 0 
				    			|| this.bodyBox.childNodes[0] !== this.monthBox) {
				    		this._setHtml(this.bodyBox, "", false);
				    	    this.bodyBox.appendChild(this.monthBox);
				    	}				    	
				    	this._refreshMonthBox();
				    }
					break;
				case this.cyctypes.ten : break;			
				case this.cyctypes.day :
				    //日期选择
					if(this.isEmpty(this.dayBox) || this.dayBox.rows.length == 0) {
						this._setHtml(this.bodyBox, "", false);
					    this.dayBox = this._getDayBox();
					    this.bodyBox.appendChild(this.dayBox);
					} else {
						if(this.bodyBox.childNodes.length === 0 
				    			|| this.bodyBox.childNodes[0] !== this.dayBox) {
							this._setHtml(this.bodyBox, "", false);
				    	    this.bodyBox.appendChild(this.dayBox);
				    	}	
						this._refreshDayBox();
					}		
				    break;
				case this.cyctypes.hour :
					//选择时间
					if(this.isEmpty(this.hourBox) || this.hourBox.rows.length == 0) {
						this._setHtml(this.bodyBox, "", false);
						this.hourBox = this._getHourBox();
						this.bodyBox.appendChild(this.hourBox);
					} else {
						if(this.bodyBox.childNodes.length === 0
								|| this.bodyBox.childNodes[0] !== this.hourBox) {
							this._setHtml(this.bodyBox, "", false);
							this.bodyBox.appendChild(this.hourBox);
						}
						this._refreshHourBox();
					}
					break;
				case this.cyctypes.minute :
					//选择时间
					if(this.isEmpty(this.minuteBox) || this.minuteBox.rows.length == 0) {
						this._setHtml(this.bodyBox, "", false);
						this.minuteBox = this._getMinuteBox();
						this.bodyBox.appendChild(this.minuteBox);
					} else {
						if(this.bodyBox.childNodes.length === 0
								|| this.bodyBox.childNodes[0] !== this.minuteBox) {
							this._setHtml(this.bodyBox, "", false);
							this.bodyBox.appendChild(this.minuteBox);
						}
						this._refreshMinuteBox();
					}
					break;
				case this.cyctypes.second :
					//选择时间
					if(this.isEmpty(this.secondBox) || this.secondBox.rows.length == 0) {
						this._setHtml(this.bodyBox, "", false);
						this.secondBox = this._getSecondBox();
						this.bodyBox.appendChild(this.secondBox);
					} else {
						if(this.bodyBox.childNodes.length === 0
								|| this.bodyBox.childNodes[0] !== this.secondBox) {
							this._setHtml(this.bodyBox, "", false);
							this.bodyBox.appendChild(this.secondBox);
						}
						this._refreshSecondBox();
					}
					break;
				default : break;
			}
			//footer
			this._refreshFooter();
		},
		/**
		 * 设置日期.
		 * @param date 日期
		 */
	    setDate:function(date, refresh) {
	    	if (date != null) {
	    		date = this.checkDate(date);
	    		if(date === "") {
	    			date = new Date();
	    		}
	    		var djs = this._decodeDateTime(date);
	    		this.curYear = djs.year;
	    		this.curMonth = djs.month;
	    		this.curDay = djs.day;
	    		if(this.cyctype === this.cyctypes.day && this.showTime) {
	    			this.hTime.setValue(0);
	    			this.mTime.setValue(0);
	    			this.sTime.setValue(0);
	    		} else if(this.cyctype === this.cyctypes.hour || this.cyctype === this.cyctypes.minute 
	    				|| this.cyctype === this.cyctypes.second) {
	    			this.curHour = djs.hour;
	    			this.curMinute = djs.minute;
	    			this.curSecond = djs.secnod;
	    		}
	    		if(refresh !== false) {
	    		    this.refreshCalendar();
	    		}
	        }
	    },
	    /**
	     * 解析时间/日期字符串，及时间/日期对象.
	     * @param date 时间
	     * @return 返回时间json对象
	     */
	    _decodeDateTime:function(date) {
	    	var re = null;
	    	if(date != null && date !== "") {
	    		re = {};
	    		var y, m, d, hh, mm, ss;
	    		if(typeof date === "string") {
	    			var strs = date.split(this.dtSplit);
	    			var slen = strs.length;
	    			re.year = parseInt(strs[0], 10);	    			
	    			if(slen > 1) {
	    			    re.month = parseInt(strs[1], 10);
	    			}
	    			if(slen > 2) {
	    			    re.day = parseInt(strs[2], 10);
	    			}
	                if(this.cyctype === this.cyctypes.day && this.showTime 
	                		|| this.cyctype === this.cyctypes.hour 
	                		    || this.cyctype === this.cyctypes.minute
	                		       || this.cyctype === this.cyctypes.second) {
	                	if(strs.length > 3 && strs[3] !== "") {
		                	var cts = strs[3].split(/[:.]/g);
		                	var clen = cts.length;
		                	re.hour = cts[0];
		                	re.minute = cts[1];
		                	re.second = cts[2];
		                	if(clen > 3) {
		                		re.msecond = cts[3];
	                	    }
	                	} else {
	                		var ctm = this._getCurTime();
	                		re.hour = ctm.h;
	                		re.minute = ctm.m;
	                		re.second = ctm.s;
	                	}
	                }	
	                //如果传入的是非法日期，则初始化为当前日期.
	                if(isNaN(re.year)) {
	                	var date = new Date();
	                	re.year = date.getFullYear();
		    			re.month = date.getMonth() + 1;
		    			re.day = date.getDate();
		    			var ctm = this._getCurTime();
                		re.hour = ctm.h;
                		re.minute = ctm.m;
                		re.second = ctm.s;
	                }
	    		} else {
	    			date = new Date();
	    			re.year = date.getFullYear();
	    			re.month = date.getMonth() + 1;
	    			re.day = date.getDate();
	    			if(this.cyctype === this.cyctypes.day && this.showTime 
	                	|| this.cyctype === this.cyctypes.hour 
                		    || this.cyctype === this.cyctypes.minute
                		       || this.cyctype === this.cyctypes.second) {
	    				var ctm = this._getCurTime();
                		re.hour = ctm.h;
                		re.minute = ctm.m;
                		re.second = ctm.s;	                		
	                }
	    		}
	    	}
	    	return re;
	    },
	    /**
	     * 获取时间.
	     */
	    _getCurTime:function(date) {
	    	return this.dateObj._getCurTime(date);
	    },
	    /**
	     * 设置最大日期.
	     * @param date 日期
	     */
	    setMaxDate:function(date, refresh) {
	    	if (date != null) {
	    		date = this.checkDate(date);
	    		if(date !== "") {
	    			var djs = this._decodeDateTime(date);
	                this.maxYear = djs.year;
	                this.maxMonth = djs.month;
	                this.maxDay = djs.day;		            
	    		} else {
	    			this.maxYear = 9999;
	                this.maxMonth = 12;
	                this.maxDay = 31;
	    		}
	    		if(refresh !== false) {
	    		    this.refreshCalendar();
	    		}
	        }
	    },
	    /**
	     * 设置最小日期.
	     * @param date 日期
	     */
	    setMinDate:function(date, refresh) {
	    	if (date != null) {
	    		date = this.checkDate(date);
	    		var h, m, s, ht = false;
	    		if(date !== "") {
	    			var djs = this._decodeDateTime(date);
	    			this.minYear = djs.year;
	                this.minMonth = djs.month;
	                this.minDay = djs.day;          
	    		} else {
	    			this.minYear = 1;
	                this.minMonth = 1;
	                this.minDay = 1;
	    		}
	    		if(refresh !== false) {
	    		    this.refreshCalendar();
	    		}
	        }
	    },
	    /**
	     * 设置是否显示时间 .
	     * @param value 状态
	     */
	    setShowTime:function(value) {
	    	this.showTime = this.isEmpty(value)?false:Boolean(value);
	    	if(this.cyctype === this.cyctypes.day && this.showTime) {
	    		this.timeRow.style.display = "";
	    		this.setHeight(this._sumHeight + 32);
	    	} else {
	    		this.timeRow.style.display = "none";
	    		this.setHeight(this._sumHeight);
	    	}
	    	//初始化对象的显示时间属性
	    	this.dateObj.setShowTime(this.showTime);
	    },
	    /**
	     * 日期周期.
	     */
	    setCycType:function(value) {
	    	this.cyctype = value;
	    	if(this.cyctype == this.cyctypes.hour || this.cyctype == this.cyctypes.minute 
	    			|| this.cyctype == this.cyctypes.second) {
	    		this.curCyctype = this.cyctypes.day;
	    	} else {
	    	    this.curCyctype = this.cyctype;
	    	}
	    	this.dateObj.setCycType(this.cyctype);
	    	this.refreshCalendar(false);
	    },
	    /**
	     * 获取日期.
	     * @return 日期
	     */
	    getDate:function(){
	    	var y = parseInt(this.curYear, 10);
	    	var m = parseInt(this.curMonth, 10);
	    	var d = parseInt(this.curDay, 10);	    	
	    	if(y < 100) {
	    		y = "20" + y;
	    	}
	    	if(m < 10) {
	    		m = "0" + m;
	    	}
	    	if(d < 10) {
	    		d = "0" + d;
	    	}
	    	var re = y + this.dateSplit + m + this.dateSplit + d; 
	    	if(this.cyctype === this.cyctypes.day && this.showTime) {
	    		var ts = " ";
	    		ts += this.hTime.getText() + this.timeSplit;
	    		ts += this.mTime.getText() + this.timeSplit;
	    		ts += this.sTime.getText();
	    		re += ts;
	    	} else if(this.cyctype === this.cyctypes.hour) {
	    		var ts = " ";
	    		ts += this.curHour + this.timeSplit + "00" + this.timeSplit + "00";
	    		re += ts;
	    	} else if(this.cyctype === this.cyctypes.minute) {
	    		var ts = " ";
	    		var ms = this.curMinute;
	    		if(typeof ms == "number" && ms < 10 || typeof ms == "string" && ms.length == 0) {
	    			ms = "0" + ms;
	    		}
	    		ts += this.curHour + this.timeSplit + ms + this.timeSplit + "00";
	    		re += ts;
	    	} else if(this.cyctype === this.cyctypes.second) {
	    		var ts = " ";
	    		var ms = this.curMinute;
	    		if(typeof ms == "number" && ms < 10 || typeof ms == "string" && ms.length == 0) {
	    			ms = "0" + ms;
	    		}
	    		var ss = this.curSecond;
	    		if(typeof ss == "number" && ss < 10 || typeof ss == "string" && ss.length == 0) {
	    			ss = "0" + ss;
	    		}
	    		ts += this.curHour + this.timeSplit + ms + this.timeSplit + ss;
	    		re += ts;
	    	}
	    	return re;
	    }
	});
	/**
	 * 单列实例.
	 */
	qzz.ui.calendar.instance = null;
	/**
	 * 获取单列对象.
	 */
	qzz.ui.calendar.getInstance = function(cssPrefix) {
		if(cssPrefix === null) {
			cssPrefix = "";
		}
		if(qzz.ui.calendar.instance == null) {
			qzz.ui.calendar.instance = new qzz.ui.calendar(undefined, {"cssPrefix":this._cssPrefix});
			qzz.ui.calendar.instance._notFree = true;
		}
		qzz.ui.calendar.instance._setCssPrefix(cssPrefix);
		return qzz.ui.calendar.instance;
	};
	_bindRenderFunc("qzzcalendar", qzz.ui.calendar);
	return qzz.ui.calendar;
});